//
//  AllWarnHeaderView.m
//  Rail
//
//  Created by hychen on 2018/2/28.
//  Copyright © 2018年 Hychen. All rights reserved.
//

#import "AllWarnHeaderView.h"
#import "SCPieChart.h"

#define kDoneColor Color_RGB(0, 193, 224)
//#define kUndoneColor Color_RGB(74, 224, 34)
#define kUndoneColor Color_RGB(74, 224, 34)

@interface AllWarnHeaderView ()

@property (weak, nonatomic) IBOutlet UIView *circleView;
@property (weak, nonatomic) IBOutlet UILabel *finishNumLabel;
@property (weak, nonatomic) IBOutlet UILabel *todoNumLabel;

@property (weak, nonatomic) IBOutlet UILabel *normalNumLabel;
@property (weak, nonatomic) IBOutlet UILabel *warnNumLabel;
@property (weak, nonatomic) IBOutlet UILabel *serivousNumLabel;
@property (weak, nonatomic) IBOutlet UILabel *heavyNumLabel;

@property (nonatomic, strong) SCPieChart *pieChart;

@property (weak, nonatomic) IBOutlet UIView *normalView;
@property (weak, nonatomic) IBOutlet UIView *warnView;
@property (weak, nonatomic) IBOutlet UIView *serivousView;
@property (weak, nonatomic) IBOutlet UIView *heavyView;
@property (weak, nonatomic) IBOutlet UIView *finishView;
@property (weak, nonatomic) IBOutlet UIView *todoView;

@end

@implementation AllWarnHeaderView

+ (instancetype)headerView
{
    return [[[NSBundle mainBundle] loadNibNamed:@"AllWarnHeaderView" owner:self options:nil] lastObject];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    BMWeakSelf
    [self.normalView addTapGestureWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        if (weakSelf.BlockClickNormal) {
            weakSelf.BlockClickNormal();
        }
    }];
    
    [self.warnView addTapGestureWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        if (weakSelf.BlockClickWarn) {
            weakSelf.BlockClickWarn();
        }
    }];
    
    [self.serivousView addTapGestureWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        if (weakSelf.BlockClickSerivous) {
            weakSelf.BlockClickSerivous();
        }
    }];
    
    [self.heavyView addTapGestureWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        if (weakSelf.BlockClickHeavy) {
            weakSelf.BlockClickHeavy();
        }
    }];
    
    [self.finishView addTapGestureWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        if (weakSelf.BlockClickFinish) {
            weakSelf.BlockClickFinish();
        }
    }];
    
    [self.todoView addTapGestureWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        if (weakSelf.BlockClickTodo) {
            weakSelf.BlockClickTodo();
        }
    }];
    
}

- (void)setModel:(InformationAlertModel *)model {
    _model = model;
    
    self.finishNumLabel.text = model.processed_count;
    self.todoNumLabel.text = model.processing_count;
    
    self.normalNumLabel.text = model.level_0_count;
    self.warnNumLabel.text = model.level_1_count;
    self.serivousNumLabel.text = model.level_2_count;
    self.heavyNumLabel.text = model.level_3_count;
    
    [self configPieChart];
}

- (void)configPieChart {
    if (self.pieChart.superview) {
        [self.pieChart removeFromSuperview];
        self.pieChart = nil;
    }

    NSArray *items = @[[SCPieChartDataItem dataItemWithValue:[self.model.processed_count integerValue] color:kDoneColor description:@"已处理"],
                       [SCPieChartDataItem dataItemWithValue:[self.model.processing_count integerValue] color:[UIColor redColor] description:@"未处理"],
                       ];
    
    self.pieChart = [[SCPieChart alloc] initWithFrame:CGRectMake(0, 0, 60.0, 60.0) items:items];
    self.pieChart.showDescValues = NO;
    self.pieChart.descriptionTextColor = kPieChartDescColor;
    self.pieChart.descriptionTextFont  = [UIFont fontWithName:@"Avenir-Medium" size:11.0];
    [self.pieChart strokeChart];
    [self.circleView addSubview:self.pieChart];
    [self.pieChart mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.circleView);
    }];
}


@end
